package it.com.Test.a3_combinable;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestOfThenAcceptBoth {
    static ExecutorService executor = Executors.newFixedThreadPool(3);

    public static void main(String[] args) {
        System.out.println("main....start....");
        CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("任务一开始");
            System.out.println("任务一结束***");
            return 10;
        }, executor);
        CompletableFuture<Integer> task2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("任务二开始");
            try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}
            System.out.println("任务二结束***");
            return 20;
        }, executor);

        task1.thenAcceptBothAsync(task2, (r1, r2) -> {
            System.out.println("任务三开始");
            System.out.println("获取任务一结果：" + r1);
            System.out.println("获取任务二结果：" + r2);
            System.out.println("任务三结束***");
        }, executor);
        System.out.println("main....end....");
    }
    /**
     D:\DevSoft\jdk1.8.0_131\bin\java.exe "-javaagent:D:\DevSoft\IntelliJ IDEA 2022.2.3\lib\idea_rt.jar=1924:D:\DevSoft\IntelliJ IDEA 2022.2.3\bin" -Dfile.encoding=UTF-8 -classpath D:\DevSoft\jdk1.8.0_131\jre\lib\charsets.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\deploy.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\access-bridge-64.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\dnsns.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\jaccess.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\localedata.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\nashorn.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\sunec.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\ext\zipfs.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\javaws.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\jce.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\jfr.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\jfxswt.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\jsse.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\management-agent.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\plugin.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\resources.jar;D:\DevSoft\jdk1.8.0_131\jre\lib\rt.jar;D:\IdeaRepository\springboot-async\target\classes;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\boot\spring-boot-starter-web\2.3.2.RELEASE\spring-boot-starter-web-2.3.2.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\boot\spring-boot-starter\2.3.2.RELEASE\spring-boot-starter-2.3.2.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\boot\spring-boot\2.3.2.RELEASE\spring-boot-2.3.2.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\boot\spring-boot-autoconfigure\2.3.2.RELEASE\spring-boot-autoconfigure-2.3.2.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\boot\spring-boot-starter-logging\2.3.2.RELEASE\spring-boot-starter-logging-2.3.2.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\maven\apache-maven-3.6.1\maven_repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;D:\maven\apache-maven-3.6.1\maven_repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\spring-core\5.2.8.RELEASE\spring-core-5.2.8.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\spring-jcl\5.2.8.RELEASE\spring-jcl-5.2.8.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\boot\spring-boot-starter-json\2.3.2.RELEASE\spring-boot-starter-json-2.3.2.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\com\fasterxml\jackson\core\jackson-databind\2.11.1\jackson-databind-2.11.1.jar;D:\maven\apache-maven-3.6.1\maven_repository\com\fasterxml\jackson\core\jackson-annotations\2.11.1\jackson-annotations-2.11.1.jar;D:\maven\apache-maven-3.6.1\maven_repository\com\fasterxml\jackson\core\jackson-core\2.11.1\jackson-core-2.11.1.jar;D:\maven\apache-maven-3.6.1\maven_repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.1\jackson-datatype-jdk8-2.11.1.jar;D:\maven\apache-maven-3.6.1\maven_repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.1\jackson-datatype-jsr310-2.11.1.jar;D:\maven\apache-maven-3.6.1\maven_repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.1\jackson-module-parameter-names-2.11.1.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\boot\spring-boot-starter-tomcat\2.3.2.RELEASE\spring-boot-starter-tomcat-2.3.2.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.37\tomcat-embed-core-9.0.37.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.37\tomcat-embed-websocket-9.0.37.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\spring-web\5.2.8.RELEASE\spring-web-5.2.8.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\spring-beans\5.2.8.RELEASE\spring-beans-5.2.8.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\spring-webmvc\5.2.8.RELEASE\spring-webmvc-5.2.8.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\spring-aop\5.2.8.RELEASE\spring-aop-5.2.8.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\spring-context\5.2.8.RELEASE\spring-context-5.2.8.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\springframework\spring-expression\5.2.8.RELEASE\spring-expression-5.2.8.RELEASE.jar;D:\maven\apache-maven-3.6.1\maven_repository\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar it.com.Test.a3_combinable.TestOfThenAcceptBoth
     main....start....
     任务一开始
     任务一结束***
     任务二开始
     main....end....
     任务二结束***
     任务三开始
     获取任务一结果：10
     获取任务二结果：20
     任务三结束***

     */
}
